package cn.xpf.study.dao;

import cn.xpf.study.model.Lesson;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * Create on 2021/5/13
 *
 * @author shuxinsheng@qiyi.com
 **/
@Mapper
public interface LessonMapper {
    String table = "lesson";

    @Select("select count(*) from lesson")
    int count();

    @Select("select * from " + table + " where id=#{id}")
    Lesson findById(@Param("id") int id);

    @Select("select * from " + table + " where deleted != 1 order by `order` asc")
    List<Lesson> findAll();

    @Update("update " + table + " set `name`=#{lesson.name},`order`=#{lesson.order},`title`=#{lesson.title},`image`=#{lesson.image},`desc`=#{lesson.desc},`status`=#{lesson.status} where id=#{lesson.id}")
    void updateOne(@Param("lesson") Lesson lesson);

    @Update("insert into " + table + "(`order`,`name`,`title`,`desc`,`image`,`status`) value(#{lesson.order},#{lesson.name},#{lesson.title},#{lesson.desc},#{lesson.image},#{lesson.status})")
    void insertOne(@Param("lesson") Lesson lesson);

    @Update("update " + table + " set `deleted`=1 where id=#{lessonId}")
    void deleteOne(@Param("lessonId") int lessonId);

}
